package com.sci.controller;


import com.sci.entity.Business;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.sci.entity.Order;
import com.sci.entity.User;

@RestController
@RequestMapping("order")
public class OrderController {

    @Resource
    private RestTemplate restTemplate;
    @GetMapping("/{orderId}")
    public Order getUser(@PathVariable(value = "orderId") String orderId) {
        Order order = new Order();
        order.setOrderId(orderId);
        order.setPrice(66.6);
        String url = "http://user-service/user/" + "101";
        User user = restTemplate.getForObject(url, User.class);
        String url2 = "http://business-service/business/" + "103";
        Business business = restTemplate.getForObject(url2, Business.class);
        order.setUser(user);
        order.setBusiness(business);
        return order;
    }
}
